package com.xdkj.controller;

import com.xdkj.pojo.Student;
import com.xdkj.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author ：李浩(Anthony)
 * @description：
 * @date ：Created in 2021/10/21 14:57
 */
@RestController
public class StuController {
   @Autowired
   StuService stuService;
    //查询

    @GetMapping("/del")
    public ModelAndView del(HttpServletRequest request){
        int sid =Integer.parseInt(request.getParameter("sid"));
        stuService.Del(sid);
        return new ModelAndView("redirect:/Display");
    }
    @GetMapping("/addPage")
    public ModelAndView addPage(Model model){
        model.addAttribute("student",new Student());
        return new ModelAndView("add","stuModel",model);

    }
    @PostMapping("/add")
    public ModelAndView add(Student student){
        stuService.Add(student);
        return new ModelAndView("redirect:/Display");
    }
    @GetMapping("/sendsid")
    public ModelAndView sendsid(HttpServletRequest request,Model model){
        int sid =Integer.parseInt(request.getParameter("sid"));
        Student list = stuService.selectByPrimaryKey(sid);
        model.addAttribute("list",list);
        return new ModelAndView("Edit","stuModel",model);
    }
    @PostMapping("/update")
    public ModelAndView update(Student student){
        stuService.Update(student);
        return new ModelAndView("redirect:/Display");
    }
}
